﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Common;
using Medicalsystem.MCP.FormDesigner.Define;
using Medicalsystem.MCP.FormDesigner.Interface;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 容器控件
    /// </summary>
    [ToolboxItem(false)]
    public class PanelCtl : System.Windows.Forms.Panel, ICtrlContainer
    {
        public PanelCtl() { }

        public PanelCtl(Model model) : this(model, EDesignModeState.Run) { }

        public PanelCtl(Model model, EDesignModeState designModeState)
        {
            this.TabStop = false;
            this.AutoScroll = true;
            this.BorderStyle = BorderStyle.FixedSingle;

            _model = model;
            _designModeState = designModeState;
            _controlContainers = new List<System.Windows.Forms.Control>();
            _controlContainers.Add(this);
        }

        private EDesignModeState _designModeState = EDesignModeState.Run;
        private List<System.Windows.Forms.Control> _controlContainers = null;
        private Model _model;

        protected GetCtrlUIProperty _propertyObject = null;
        protected bool _visibleZ = true;

        #region ICtrlContainer 成员

        public List<System.Windows.Forms.Control> ControlContainers
        {
            get { return _controlContainers; }
        }

        #endregion ICtrlContainer 成员

        #region ICtrlBase 成员

        public string CtrlID
        {
            get
            {
                return this.Name;
            }
            set
            {
                this.Name = value;
            }
        }

        public Model Model
        {
            get
            {
                return _model;
            }
        }

        public EDesignModeState DesignModeState
        {
            get
            {
                return _designModeState;
            }
            set
            {
                _designModeState = value;
            }
        }

        public virtual GetCtrlProperty PropertyObject
        {
            get
            {
                if (this._propertyObject == null)
                {
                    this._propertyObject = new GetPanelCtlProperty(this);
                }

                return this._propertyObject;
            }
        }

        public virtual EUISizeMode UISizeMode
        {
            get { return EUISizeMode.AllowBoth; }
        }

        #endregion ICtrlBase 成员

        #region ICtrlUI 成员

        public string ShowText
        {
            get
            {
                return "";
            }
            set
            {
            }
        }

        public bool VisibleZ
        {
            get
            {
                return _visibleZ;
            }
            set
            {
                _visibleZ = value;
            }
        }

        public EBorderStyle BorderStyleZ
        {
            get
            {
                return BorderStyleConvert.ToEBorderStyle(this.BorderStyle);
            }
            set
            {
                this.BorderStyle = BorderStyleConvert.ToBorderStyle(value);
            }
        }

        #endregion ICtrlUI 成员

        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    if (_designModeState == EDesignModeState.Design)
        //    {
        //        System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.DimGray);
        //        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        //        e.Graphics.DrawRectangle(pen, new System.Drawing.Rectangle(new System.Drawing.Point(1, 1), new System.Drawing.Size(this.Width - 2, this.Height - 2)));
        //    }

        //    // 调用基类 OnPaint
        //    base.OnPaint(e);
        //}

        #region IXMLConvertor 成员

        public virtual string ToXML()
        {
            PanelCtlPropertyXML XML = new PanelCtlPropertyXML(this);
            return XML.ToXML();
        }

        public void FromXML(string strXML)
        {
            if (strXML.Length > 0)
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(strXML);

                FromXML(doc.DocumentElement.ChildNodes);
            }
        }

        public virtual void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                PanelCtlPropertyXML XML = new PanelCtlPropertyXML(this);
                XML.FromXML(xns);
            }
        }

        #endregion IXMLConvertor 成员

        #region ICtrlBase 成员


        public System.Drawing.Image IcoForToolBox
        {
            get { return Properties.Resources.PropertiesHS; }
        }

        #endregion
    }
}